package com.resou.reader.bookstore.rank.adapter;

import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.resou.reader.R;
import com.resou.reader.api.entry.TypeResultBean;
import com.resou.reader.utils.TextUtils;

import java.util.List;

/**
 * Author: 萤火虫
 * E-mail:  Allensuns@163.com
 * Description: 排行榜类容适配器
 * CreateTime: 2019-04 -09
 **/
public class RankContentAdapter extends BaseQuickAdapter<TypeResultBean.BookListBean, BaseViewHolder> {

    public RankContentAdapter(int layoutResId, @Nullable List<TypeResultBean.BookListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, TypeResultBean.BookListBean item) {
        helper.addOnClickListener(R.id.mConstraintLayout);
        Glide.with(mContext).load(item.getBookCover()).apply(new RequestOptions().placeholder(R.mipmap.ic_place)).
                into((ImageView) helper.getView(R.id.poster_image));
        helper.setText(R.id.book_name_text, helper.getAdapterPosition() + 1 + "." + item.getBookName() + "");
        helper.setText(R.id.tvAuthor, item.getBookAuthor() + "");
        helper.setText(R.id.description_text, TextUtils.formatText(item.getBookIntro()));
        helper.setText(R.id.tvLabel, item.getRankVal() + "");
//        helper.setText(R.id.tvFontNum, TextUtils.caclFontNum(item.getTotalWord()));
        helper.setText(R.id.tvFontNum, item.getBookWords() + "");
        helper.setText(R.id.tvType, "·" + item.getBookCategory() + "·");
    }

    /**
     * 获取标签结尾值
     *
     * @param state
     * @return
     */
    private String getLabel(int state) {
        switch (state) {
            /**
             * 月票榜
             */
            case 0:
                return "月票";
            /**
             * 热搜榜
             */
            case 1:
                return "热搜";
            /**
             * 点击榜
             */
            case 2:
                return "点击";
            /**
             * 免费榜
             */
            case 3:
                return "人气";
            /**
             * 完结榜
             */
            case 4:
                return "人气";
            /**
             * 新书榜
             */
            case 5:
                return "阅读";
            /**
             * 收藏榜
             */
            case 6:
                return "收藏";
        }
        return "";
    }
}
